package com.px.service;


import com.px.entity.HttpParame;
import org.springframework.stereotype.Service;

@Service
public class WeixinLoginServiceImpl implements WeixinLoginService {
    /**
     * 微信扫码登录请求地址生成
     *
     * @return
     */
    @Override
    public String genLoginUrl() {

        //获取网页授权地址
        String url = HttpParame.AUTHORIZATION_URL;
//        //获取appid   网站应用生成给的
//        url = url.replaceAll("APPID", PropertiesUtil.getValue(HttpParame.APPID));
//        try {
//            //官方文档要求要使用urlEncode对链接进行处理
//            url = url.replaceAll("REDIRECT_URI", URLEncoder.encode(
//                    //获取网页的回调地址
//                    PropertiesUtil.getValue(HttpParame.REDIRECT_URI),"UTF-8"));
//        } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
//        }
//        //固定的
//        url = url.replaceAll("SCOPE", "snsapi_login");
        return url;
    }


//    @Override
//    public AccessToken getAccessToken(String code) {
//        String accessTokenUrl = HttpParame.ACCESS_TOKEN_URL;
//        accessTokenUrl = accessTokenUrl.replaceAll("APPID", PropertiesUtil.getValue(HttpParame.APPID));
//        accessTokenUrl = accessTokenUrl.replaceAll("SECRET", PropertiesUtil.getValue(HttpParame.SECRET));
//        accessTokenUrl = accessTokenUrl.replaceAll("CODE", code);
//        String responseContent = HttpClientUtil.getInstance().sendHttpGet(accessTokenUrl);
//        if (responseContent == null || responseContent == "") {
//            return null;
//        }
//        JSONObject parseObject = JSONObject.parseObject(responseContent);
//        AccessToken accessToken = JSONObject.toJavaObject(parseObject, AccessToken.class);
//        return accessToken;
//    }
//
//    @Override
//    public WechatUserUnionID getUserUnionID(String access_token, String openid) {
//        String unionIDUrl = HttpParame.GET_UNIONID_URL;
//        unionIDUrl = unionIDUrl.replace("ACCESS_TOKEN", access_token);
//        unionIDUrl = unionIDUrl.replace("OPENID", openid);
//        String responseContent = HttpClientUtil.getInstance().sendHttpGet(unionIDUrl);
//        System.out.println("responseContent:"+responseContent);
//        if (responseContent == null || responseContent == "") {
//            return null;
//        }
//        JSONObject parseObject = JSONObject.parseObject(responseContent);
//        WechatUserUnionID userUnionID = JSONObject.toJavaObject(parseObject, WechatUserUnionID.class);
//        return userUnionID;
//    }
}
